package com.qidian.mes.cal.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.cal.mapper.CalTeamMemberMapper;
import com.qidian.mes.cal.service.CalTeamMemberService;
import com.qidian.mes.pojo.CalTeamMember;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author zhangYu
 * @Company 起点编程
 * @Time 2023/10/27 10:18
 * @Description
 */
@Service
public class CalTeamMemberServiceImpl implements CalTeamMemberService {
    @Autowired
    CalTeamMemberMapper calTeamMemberMapper;
    @Override
    public MESResult get(Long memberId) {
        return MESResult.ok(calTeamMemberMapper.get(memberId));
    }

    @Override
    public MESResult save(CalTeamMember calTeamMember) {
        if (calTeamMemberMapper.save(calTeamMember)>0) {
            MESResult.ok();
        }
        return MESResult.fail();
    }
    @Override
    public MESResult list(int page, int limit, CalTeamMember calTeamMember) {
        // 开启分页 在当前线程中执行下一条SQL的时候就会进行分页。
        PageHelper.startPage(page,limit);
        List<CalTeamMember> list = calTeamMemberMapper.list(calTeamMember);
        // 组织一个分页对象。（页码，每页大小，最大页码，数据，总条数）
        PageInfo<CalTeamMember> pageInfo = new PageInfo<>(list);
        return MESResult.ok(pageInfo);
    }
}
